package com.qingyun.edusysteam.utils;

import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

import static com.qingyun.edusysteam.utils.RedisConstants.PDF_TASK_QUEUE;

/**
 * Redis Stream消息生产者
 */
@Component
public class StreamMessageProducer {

    private final RedisTemplate<String, Object> redisTemplate;

    public StreamMessageProducer(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 发送消息到Stream
     */
    public RecordId sendMessage(String feedbackId, String userId, double amount) {
        // 创建消息内容
        Map<String, Object> message = new HashMap<>();
        message.put("feedbackId", feedbackId);
        // 发送消息到Stream，返回消息ID
        ObjectRecord<String, Map<String, Object>> record = ObjectRecord.create(PDF_TASK_QUEUE, message);
        return redisTemplate.opsForStream().add(record);
    }
}
    